<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>出库记录页</title>
<!-- 下载并引入jquery easyUI -->
<link rel="stylesheet" type="text/css"
	href="${param.request.contextPath}/jquery-easyui-1.8.8/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${param.request.contextPath}/jquery-easyui-1.8.8/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${param.request.contextPath}/kindeditor/themes/default/default.css">
<link rel="stylesheet" type="text/css"
	href="${param.request.contextPath}/jquery-easyui-1.8.8/themes/color.css">
<script type="text/javascript"
	src="${param.request.contextPath}/jquery-easyui-1.8.8/jquery.min.js"></script>
<script type="text/javascript"
	src="${param.request.contextPath}/jquery-easyui-1.8.8/jquery.easyui.min.js"></script>

<style type="text/css">
#news_dlg div {
	margin-top: 10px;
}
</style>
</head>
<body>
	<!-- 在页面中使用easyUI组件进行界面编程，数据列表页面 -->
	<table id="outstorage_dg" title="出库记录列表" class="easyui-datagrid"
		style="width: 100%; height: 453px"
		url="${pageContext.request.contextPath}/outstorage/list"
		toolbar="#outstorage_toolbar" pagination="true" rownumbers="true"
		fitColumns="true" singleSelect="true">
		<thead>
			<tr>
				<th field="cb" checkbox="true" align="center" width="50" height="45"></th>
				<!-- field字段名需要与返回数据的属性名一致 -->
				<th field="outStoId" width="50">出库信息编号</th>
				<th field="carId" formatter="carFormatter" width="50">出库汽车</th>
				<th field="storageId" formatter="storageFormatter" width="50">仓库名称</th>
				<th field="outCause" width="50">出库原因</th>
				<th field="restockId" width="50">采购退货单</th>
				<th field="saleId" width="50">销售订货单</th>
				<th field="outStoDate" formatter="dateFormatter" width="50">出库时间</th>
				<th field="emp" formatter="empFormatter" width="50">办理人</th>
				<th field="remark" width="50">备注</th>

			</tr>
		</thead>
	</table>
	<!-- 工具条 -->
	<div id="outstorage_toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="newoutSto()">新增</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editoutSto()">修改</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyoutSto()">删除</a>
	</div>

	<!-- 新增和修改数据 -->
	<div id="outstorage_dlg" class="easyui-dialog"
		style="width: 800px; height: 600px; padding: 10px 20px" closed="true"
		buttons="#outstorage_dlg-buttons">
		<div class="ftitle">信息管理</div>
		<form id="outstorage_fm" enctype="multipart/form-data" method="post">
			<div class="fitem">
				<label>汽车名称:</label> <input id="carName" name="car.carId"
					class="easyui-combobox" required="true"
					data-options="valueField:'carId',textField:'carName',url:'${param.request.contextPath}/car/findall'">
			</div>
			<br>
			<div class="fitem">
				<label>出货仓库:</label> <input id="storageName"
					name="storage.storageId" class="easyui-combobox" required="true"
					data-options="valueField:'storageId',textField:'storageName',url:'${param.request.contextPath}/storage/findall'">
			</div>
			<br>
			<div class="fitem">
				<label>出库原因:</label> <label>采购退货：</label> <input name="outCause"
					class="easyui-radiobutton" value="采购退货" />&nbsp;&nbsp;&nbsp;&nbsp;<label>销售售出：</label><input
					name="outCause" class="easyui-radiobutton" value="销售售出" />
			</div>
			<br>
			<div class="fitem">
				<label>退货单号:</label> <input name="restockId"
					class="easyui-validatebox">
			</div>
			<br>
			<div class="fitem">
				<label>销售单号:</label> <input name="saleId"
					class="easyui-validatebox">
			</div>
			<br>
			<%-- <div class="fitem">
				<label>入库原因-进货:</label> <input id="newsAdmin" name="admin.adminId"
					class="easyui-combobox" required="true"
					data-options="valueField:'adminId',textField:'adminNickname',url:'${param.request.contextPath}/admin/findall'">
			</div>
			<div class="fitem">
				<label>入库原因-退回:</label> <input id="newsType" name="type.typeId"
					class="easyui-combobox" required="true"
					data-options="valueField:'typeId',textField:'typeName',url:'${param.request.contextPath}/type/findall'">
			</div> --%>
			<div class="fitem">
				<label>入库时间:</label> <input type="text" name="outStoDate"
					class="easyui-datebox">
			</div>
			<br>
			<div class="fitem">
				<label>办理人:</label> <input id="empName" name="emp.empId"
					class="easyui-combobox" required="true"
					data-options="valueField:'empId',textField:'empName',url:'${param.request.contextPath}/emp/findall'">
			</div>
			<br>
			<div class="fitem">
				<label>备注:</label> <input name="remark" class="easyui-texteditor"
					title="TextEditor" data-options="multiline:true"
					style="width: 600px; height: 100px">
			</div>
		</form>
	</div>

	<div id="outstorage_dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="save()">保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#outstorage_dlg').dialog('close')">取消</a>
	</div>

	<script type="text/javascript">
		function carFormatter(value, row, index) {
			return row.car.carName;
		}

		function storageFormatter(value, row, index) {
			return row.storage.storageName;
		}

		function empFormatter(value, row, index) {
			return row.emp.empName;
		}

		function dateFormatter(value, row, index) {
			var date = new Date(value);
			var y = date.getFullYear();
			var m = date.getMonth() + 1;
			var d = date.getDate();
			return y + '-' + (m < 10 ? ('0' + m) : m) + '-'
					+ (d < 10 ? ('0' + d) : d);
		}

		function loadCar(car) {
			var data = $("#carName").combobox("getData");
			if (data && data.length > 0) {
				if (car == 0) {
					$("#carName").combobox("setValue", data[0].carId);
				} else {
					$("#carName").combobox("setValue", car);
				}
			}
		}

		function loadStorage(storage) {
			var data = $("#storageName").combobox("getData");
			if (data && data.length > 0) {
				if (storage == 0) {
					$("#storageName").combobox("setValue", data[0].storageId);
				} else {
					$("#storageName").combobox("setValue", storage);
				}
			}
		}

		function loadEmp(emp) {
			var data = $("#empName").combobox("getData");
			if (data && data.length > 0) {
				if (emp == 0) {
					$("#empName").combobox("setValue", data[0].empId);
				} else {
					$("#empName").combobox("setValue", emp);
				}
			}
		}

		function newoutSto() {
			$('#outstorage_dlg').dialog('open').dialog('setTitle', '新增记录');
			$('#outstorage_fm').form('clear');
			url = '${pageContext.request.contextPath}/outstorage/add';
		}

		function editoutSto() {
			$('#outstorage_fm').form('clear');
			var row = $('#outstorage_dg').datagrid('getSelected');
			if (row) {
				$('#outstorage_dlg').dialog('open').dialog('setTitle', '修改记录');
				$('#outstorage_fm').form('load', row);
				url = '${pageContext.request.contextPath}/outstorage/edit?outStoId='
						+ row.outStoId;
			}
			loadCar(row.car.carId);
			loadStorage(row.storage.storageId);
			loadEmp(row.emp.empId);
		}

		function save() {
			$('#outstorage_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (!result.success) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$.messager.show({
							title : 'Info',
							msg : result.errorMsg
						});
					}

					$('#outstorage_dlg').dialog('close'); // close the dialog
					$('#outstorage_dg').datagrid('reload'); // reload the user data
				}
			});
		}

		function destroyoutSto() {
			var row = $('#outstorage_dg').datagrid('getSelected');
			if (row) {
				$.messager
						.confirm(
								'Confirm',
								'确认删除记录?',
								function(r) {
									if (r) {
										$
												.post(
														'${pageContext.request.contextPath}/outstorage/delete',
														{
															outStoId : row.outStoId
														},
														function(result) {
															if (result.success) {
																$(
																		'#outstorage_dg')
																		.datagrid(
																				'reload'); // reload the user data
															} else {
																$.messager
																		.show({ // show error message
																			title : 'Error',
																			msg : result.errorMsg
																		});
															}
														}, 'json');
									}
								});
			}
		}
	</script>

</body>
</html>